package com.example.service.impl;

import com.example.pojo.ContactsGroupDetail;
import com.example.mapper.ContactsGroupDetailMapper;
import com.example.service.IContactsGroupDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import com.example.vo.reqvo.CollectContactParams;
import com.example.vo.respvo.ContactsGroupVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 联系人分组详情表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-05-14
 */
@Service
public class ContactsGroupDetailServiceImpl extends ServiceImpl<ContactsGroupDetailMapper, ContactsGroupDetail> implements IContactsGroupDetailService {

    @Override
    @Transactional
    public ResultVo insertContactsGroupDetail(CollectContactParams collectContactParams) {
        collectContactParams.getEmpIds().forEach(e->{
            ContactsGroupDetail contactsGroupDetail = new ContactsGroupDetail();
            contactsGroupDetail.setContactsGroupId(collectContactParams.getGroupId()).setEmpId(e);
            baseMapper.insert(contactsGroupDetail);
        });
        return ResultVo.ok();
    }

    @Override
    public ResultVo getContactsGroupDetailPageInfo(Integer empId) {
        List<ContactsGroupVo> contactsGroupVos = baseMapper.selectUserContactsGroupData(empId);
        return ResultVo.response(contactsGroupVos);
    }

    @Override
    public ResultVo getJoinedGroup(Integer empId, Integer targetEmpId) {
        List<Integer> joinedGroupIds = baseMapper.selectJoinedGroup(empId,targetEmpId);
        return ResultVo.response(joinedGroupIds);
    }
}
